package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {


    @RequestMapping("/login")
    public String test(String username, String password, Model model, HttpSession session) {

        // 有登录参数进来，登录模式
        if (username != null && password != null) {
            if (username.equals("admin") && password.equals("admin")) { // 登录成功
                session.setAttribute("username", "admin");
                return "redirect:/result/content";
            } else {
                model.addAttribute("message", "登录失败！");
            }

        }

        return "login";
    }
}
